package com.tac.service.wms.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.wms.MaterialInventoryDao;
import com.tac.pojo.wms.MaterialInventory;
import com.tac.service.wms.MaterialInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaterialInventoryServiceImpl implements MaterialInventoryService {

    @Autowired
    private MaterialInventoryDao materialInventoryDao;

    @Override
    public Result<PageInfo<MaterialInventory>> getList(Integer pageNum, Integer pageSize, String name, String model, String specifications) {
        PageHelper.startPage(pageNum, pageSize);
        List<MaterialInventory> list = materialInventoryDao.getList(name, model, specifications);
        PageInfo<MaterialInventory> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    @Override
    public Result save(MaterialInventory materialInventory) {
        Integer count = materialInventoryDao.save(materialInventory);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("添加失败");
        }
    }

    @Override
    public Result remove(List<Integer> ids) {
        Integer count = materialInventoryDao.remove(ids);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("删除失败");
        }
    }

    @Override
    public Result update(MaterialInventory materialInventory) {
        Integer count = materialInventoryDao.update(materialInventory);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("更新失败");
        }
    }
}
